package net.hn.hnms.biz.safety.trinity.dao;

import net.hn.hnms.biz.safety.trinity.entity.RiskControlMeasureRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

/**
 * @author 智呈物联 nzw
 * @date 2022/8/5
 */
@Repository
public interface RiskControlMeasureRecordDao extends JpaRepository<RiskControlMeasureRecord,String> {

    @Query(value = "SELECT COUNT\n" +
            "\t( * ) \n" +
            "FROM \n" +
            "\trisk_control_measure_record \n"  +
            "WHERE 1=1 \n" +
            "\tand CASE when ?1 != '' then trim(mine_code) = ?1 else 1=1 end and to_char(data_time,'yyyy-MM-dd') >= ?2",nativeQuery = true)
    int countAll(String mineCode,String dataTime);

    @Query(value = "SELECT COUNT\n" +
            "\t( * ) \n" +
            "FROM\n" +
            "\trisk_control_measure_record where risk_id = ?1" +
            "\tand CASE when ?2 != '' then trim(mine_code) = ?2 else 1=1 end",nativeQuery = true)
    int countByRiskId(String riskId,String mineCode);

    @Query(value = "SELECT COUNT\n" +
            "\t( * ) \n" +
            "FROM \n" +
            "\trisk_control_measure_record \n"+
            " where CASE when ?1 != '' then company_code = ?1 else 1=1 end",nativeQuery = true)
    int countAll(String companyCode);
}
